package com.hcbd.tdwt.ui.common.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.bd.BdToolFactory;

import java.util.List;

public class SelectBottomAdapter extends RecyclerView.Adapter<SelectBottomAdapter.MyViewHolder> {

    protected final Context mContext;
    private List<String>strList;
    private final LayoutInflater mInflater;
    private OnItemClickListener onItemClickListener;
    private int type=0;
    public SelectBottomAdapter(Context context, List<String> list) {
        mContext = context;
        mInflater = ((Activity) context).getLayoutInflater();
        strList = list;

    }
    public SelectBottomAdapter(Context context, List<String> list,int type) {
        mContext = context;
        mInflater = ((Activity) context).getLayoutInflater();
        strList = list;
        this.type=type;
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = mInflater.inflate(R.layout.item_text, viewGroup, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        String  str = strList.get(i);
        myViewHolder.itemName.setText(str);
        myViewHolder.itemName.setOnClickListener(view -> onItemClickListener.onClick(i,str));
        setBgType(myViewHolder);
    }
    public void setBgType(MyViewHolder myViewHolder){
        if(BdToolFactory.app_type== BdToolFactory.FU_DA_BG_TYPE||BdToolFactory.app_type== BdToolFactory.HAI_GE_BG_TYPE||BdToolFactory.app_type== BdToolFactory.HLCT_BG_TYPE){
            myViewHolder.itemName.setBackground(mContext.getDrawable(R.color.white));
            myViewHolder.itemName.setTextColor(mContext.getColor(R.color.black));
            myViewHolder.line.setBackground(mContext.getDrawable(R.color.lineColor));
        }
    }
    @Override
    public int getItemCount() {
        return strList.size();
    }

    public void notifyDataSetChanged(List<String> list) {
        strList = list;
        notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView itemName;
        View line;

        MyViewHolder(View itemView) {
            super(itemView);
            itemName = itemView.findViewById(R.id.item_name);
            line=itemView.findViewById(R.id.line);
        }
    }

    public interface OnItemClickListener {
        void onClick(int index,String  str);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}